/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#include "workerautoload.h"

WorkerAutoLoad::WorkerAutoLoad(QTextStream* x, LayerTrack* t) :
    WorkerProcess(1)
{
    track = t;
    stream = x;
}

bool WorkerAutoLoad::do_stuff()
{
    int n = 0;
    track->data.clear();
    track->waypoints.clear();
    while ( !stream->atEnd() )
    {
        TrackPoint temp_tp;
        TrackWaypoint temp_wp;
        QString row = stream->readLine();
        QString what = row.left(3);
        if ( what == "TP " )
        {
            if ( temp_tp.fromTxt( row.mid(3) ) )
                track->appendTrackPoint( temp_tp );
        }
        else if ( what == "WP " )
        {
            if ( temp_wp.fromTxt( row.mid(3) ) )
                track->appendWaypoint( temp_wp );
        }
        if ( (n % 10) == 0 )
        {
            sendUpdate( "...", 0, 0, 0, 0 );
            if ( please_terminate )
                return false;
        }
        n++;
    }
    sendUpdate( "...", 0, 0, 0, 0 );
    if ( please_terminate )
        return false;
    return true;
}
